package com.spring.shops.admin.controller.system;

import com.spring.shops.model.dto.PasswordDTO;
import com.spring.shops.model.dto.SysUserDTO;
import com.spring.shops.model.result.IPageIndexImg;
import com.spring.shops.model.result.ServerResponseEntityVoid;
import com.spring.shops.model.vo.SysUserVO;
import com.spring.shops.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//系统管理->用户管理
@RestController
@RequestMapping("/sys/user")
public class UserController {
    @Autowired
    private AdminService adminService;

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public ServerResponseEntityVoid<IPageIndexImg<SysUserVO>> page(SysUserDTO dto){
       return adminService.page(dto);
    }

    /**
     * 新增用户
     * @param dto
     * @return
     */
    @PostMapping
    public ServerResponseEntityVoid save(@RequestBody SysUserDTO dto){

        return adminService.save(dto);
    }

    /**
     * 根据用户ids删除数据
     * @param integers
     * @return
     */
    @DeleteMapping
    public ServerResponseEntityVoid deleteByIds(@RequestBody List<Long> integers){
         return adminService.deleteByIds(integers);
    }

    /**
     * 根据用户id获取信息
     * @param userId
     * @return
     */
    @GetMapping("/info/{userId}")
    public ServerResponseEntityVoid<SysUserVO> getInfoById(@PathVariable Long userId){
        return adminService.getInfoById(userId);
    }

    /**
     * 更新用户信息
     * @param dto
     * @return
     */
    @PutMapping
    public ServerResponseEntityVoid update(@RequestBody SysUserDTO dto){
      return adminService.update(dto);
    }

    /**
     * 修改用户密码
     * @param dto
     */
    @PostMapping("/password")
    public ServerResponseEntityVoid password(@RequestBody PasswordDTO dto){
        return adminService.password(dto);
    }

}
